package com.bawei.library_common.mvvm

import android.content.Context
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.gyf.immersionbar.ImmersionBar

/**
 * @Author : yaotianxue
 * @Time : On 2023/5/25 14:29
 * @Description : BaseActivity 所有页面公共类
 */
/**
 * 1。沉浸式状态栏
 * 2。DataBinding findViewById
 * 3。initData():数据
 * 4.initListener()：点击事件
 * 5。EventBus事件总线封装
 * 6.数据加载中，数据加载失败，数据加载成功，无网络等
 *
 */
abstract class BaseActivity<VDB:ViewDataBinding>:AppCompatActivity() {
    protected lateinit var viewDataBinding:VDB

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ImmersionBar.with(this)
            .statusBarDarkFont(true,0.2f)
            .init();
        viewDataBinding = DataBindingUtil.setContentView(this,getLayout())//initView
        initListener()
        initData()
        //调用java framework


    }
    abstract fun getLayout():Int //返回布局id
    abstract fun initData() //初始化数据
    abstract fun initListener()//事件监听
    //返回状态栏的高度
    protected fun geStatusBartHeight():Int{
         var resourceId= resources.getIdentifier("status_bar_height", "dimen", "android")
         if (resourceId > 0) {
             return resources.getDimensionPixelSize(resourceId);
         }
         return 0
     }
}